﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class index : System.Web.UI.Page
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text = "hi, " + Application["user_name"].ToString();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Application["query"] = TextBox1.Text;
        Response.Redirect("Search.aspx", true);
    }
    
    protected void ButtonExit_Click(object sender, EventArgs e)
    {
        string user_name = Application["user_name"].ToString();
        System.Data.SqlClient.SqlConnection sc = new System.Data.SqlClient.SqlConnection(Application["sqlconnection"].ToString());
        sc.Open();
        System.Data.SqlClient.SqlCommand scom = sc.CreateCommand();
        scom.CommandText = "update Users set Status=@zx where Name=@name";
        scom.Parameters.Add("@zx", System.Data.SqlDbType.Text);
        scom.Parameters.Add("@name", System.Data.SqlDbType.Text);
        scom.Parameters["@name"] = new System.Data.SqlClient.SqlParameter("@name", user_name);
        scom.Parameters["@zx"] = new System.Data.SqlClient.SqlParameter("@zx", "false");
        int count_affect = scom.ExecuteNonQuery();
        sc.Close();
       // if (count_affect == 1)
            //Response.Write("<script language=javascript>alert=('退出成功！')</script>");
        Application["user_name"] = null;//在应用程序关闭时运行的代码
        Application["query"] = null;
        Application["Email"] = null;
        Application["Gender"] = null;
        Application["Major"] = null;
        Application["password"] = null;
        Application["title"] = null;
        Application["path"] = null;
        Response.Redirect("login.aspx", true);
    }
}